package com.example.sgen_map;

import a_star.Map;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.View;

public class Draw_Map extends Activity {
	Bitmap mBitmap;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new TestView(this));

	}
}
class TestView extends View{
	private Bitmap image;
	int width;
	int height;
	float w;
	float h;
	float magnification;
	
	int split;
	float gapWidth;
	float gapHeight;
	Map map;
	
	public TestView(Context context){
		super(context);
		setFocusable(true);
		image=BitmapFactory.decodeResource(context.getResources(),com.example.sgen_map.R.drawable.map);
		
		// image info set
		width=image.getWidth();
		height=image.getHeight();
		
		// magnification is image downsize rate
		magnification = 0.6f;
		w=(float) (width*magnification);
		h=(float) (height*magnification);
		
		// how many image split slice? -> split var
		split = 50;
		
		//split gap calculate
		gapWidth = w/split;
		gapHeight = h/split;
	
		// create Map mode 1 for bind
		map = new Map(split, split, 1);
		map.createNode(w, h, split);
		
	}

	@Override
	protected void onDraw(Canvas canvas){
		// Show map.jpg
		Rect src= new Rect(0,0,width,height);
		RectF dst = new RectF(0, 0, w, h);
		Paint DivLine = new Paint();

		DivLine.setColor(Color.RED);
		canvas.drawBitmap(image, src,dst,null);

		// map function execute
		map.setCanvas(canvas);
		map.findBestPath();
		map.draw();
		
		// draw new point (using original image pixel's x,y) sample : 273,570 
		float pointX=(float) (273*magnification);
		float pointY=(float) (570*magnification);
		map.drawPoint(pointX, pointY);
		
		// grid guide line
		/*DivLine.setColor(Color.BLUE);
		for(int i = 0 ;i<split;i++){
			canvas.drawLine(0,i*gapHeight,w,i*gapHeight,DivLine);
			canvas.drawLine(i*gapWidth,0,i*gapWidth,h,DivLine);		 
		}
		*/
		super.onDraw(canvas);
		//invalidate();
	}
}